package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    /**
     * 新增订单
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 历史订单分页查询
     * @param userId
     * @return
     */
    @Select("select * from orders where user_id=#{userId} order by order_time desc ")
    List<Orders> orderHistoryPageQuery(Long userId);

    /**
     * 根据 orderId 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id =#{id}")
    Orders selectById(Long id);

    /**
     * 更新订单状态
     * @param order
     */
    //@Update("update orders set status=#{status}, cancel_time=now() where id=#{id}")
    void update(Orders order);

    /**
     * 管理端订单搜索，分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> conditionQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单状态查询
     * @param status
     * @return
     */
    @Select("SELECT count(*) from orders where status=#{status}")
    Integer selectByStatus(Integer status);

    /**
     * 查询超时订单
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time < #{time} ")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime time);

    /**
     * 当天营业额统计
     * @param map
     * @return
     */
    Double turnoverStatistics(Map map);

    /**
     * 订单统计
     * @param map
     * @return
     */
    Integer getOrderStatistics(Map map);

    /**
     * 统计销量Top10
     * @param beginTime
     * @param endTime
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
